<template>
	<view>
		<view class="flex align-center padding-lr padding-tb bg">
			<view class="u-m-r-10">
				<image :src="avatar" style="width: 100rpx;height: 100rpx;border-radius: 100rpx;"
					@click="goNav('/pages/my/userinfo')"></image>
			</view>
			<view class="u-flex-1 u-m-l-10 text-white flex align-center">
				<view class="margin-left-sm">{{userName}}</view>
			</view>
		</view>

		<view class="flex align-center box justify-between text-center">
			<view class="">
				<text class="text-bold text-xl">{{dayCount?dayCount:'0'}}</text>
				<view>今日服务量</view>
			</view>
			<view class="">
				<text class="text-bold text-xl">{{count?count:'0'}}</text>
				<view>总服务量</view>
			</view>
			<view class="">
				<text class="text-bold text-xl">{{ranKing?ranKing:'0'}}</text>
				<view>接单排名</view>
			</view>
		</view>

		<view class="margin bg padding-top" style="border-radius: 18upx;">
			<view class="flex align-center justify-between padding-lr">
				<view class="text-lg text-bold">我的订单</view>
				<view class="flex align-center" @click="goNav('/package/pages/yuangong/order')">
					查看全部
					<image src="../../../static/images/my/right.png" class="images margin-left-xs" mode=""></image>
				</view>
			</view>
			<view class="flex align-center padding-tb">
				<view class="text-center" style="width: 33%;" @click="goNav('/package/pages/yuangong/order')">
					<image src="../static/daifuwu.png" style="width: 46upx;height: 55upx;"></image>
					<view style="color: #666666;">待服务</view>
				</view>
				<view class="text-center" style="width: 33%;" @click="goNav('/package/pages/yuangong/order')">
					<image src="../static/fabu.png" style="width: 52upx;height: 52upx;"></image>
					<view style="color: #666666;">进行中</view>
				</view>
				<view class="text-center" style="width: 33%;" @click="goNav('/package/pages/yuangong/order')">
					<image src="../static/wancheng.png" style="width: 42upx;height: 52upx;"></image>
					<view style="color: #666666;">已完成</view>
				</view>
			</view>
		</view>

		<view class="bg margin radius">
			<!-- 员工管理 -->
			<view class="flex align-center padding-lr padding-tb dfs"
				@click="goNavs('/package/pages/feedbackIndex/feedbackIndex') ">
				<image src="../static/help.png" style="width: 46upx;height: 44rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">帮助中心</view>
				<image src="../../../static/images/my/right.png" class="images" mode=""></image>
			</view>
			<!-- 我的接单 -->
			<view class="flex align-center padding-lr padding-tb dfs" @click="goNavs('/my/feedback/index')">
				<image src="../static/yijian.png" style="width: 43rpx;height: 43rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">意见反馈</view>
				<image src="../../../static/images/my/right.png" class="images" mode=""></image>
			</view>
			<!-- 店铺信息 -->
			<view class="flex align-center padding-lr padding-tb dfs" @tap="goChat">
				<image src="../static/kefu.png" style="width: 46upx;height: 43rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">联系客服</view>
				<image src="../../../static/images/my/right.png" class="images" mode=""></image>
			</view>

		</view>

	</view>
</template>

<script>
	let time
	export default {
		data() {
			return {
				avatar: '../../../static/logo.png',
				userName: '匿名',
				dayCount: '',
				count: '',
				ranKing: '',
				XCXIsSelect: '是',
				userId: '',
				arr:[]
			}
		},
		onLoad() {
			this.XCXIsSelect = this.$queue.getData("XCXIsSelect");
			this.userId = this.$queue.getData("userId");
			// let that = this
			// let time = setInterval(function() {
			// 	that.getweizhi()
			// }, 5000)
			
			this.$Request.getT('/app/common/type/621').then(res => { // 派单成功通知	621
				if (res.code == 0) {
					if (res.data && res.data.value) {
						this.arr.push(res.data.value)
					}
				}
			
			})
		},
		onShow() {
			this.getweizhi()
			this.getUserInfo()
			this.getOrder()

			this.getweizhi()
		},
		onHide() {
			clearInterval(time)
		},
		methods: {
			getweizhi() { //获取员工当前位置
				let that = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						let data = {
							longitude: res.longitude,
							latitude: res.latitude
						}
						that.$Request.postJson("/app/user/updateUser", data).then(ret => {
							if (ret.code == 0) {

							}
						});
					}
				});
			},
			goNavs(e) {
				uni.navigateTo({
					url: e
				})

			},
			goNav(e, name) {
				console.log(e)
				if (this.userId) {
					// #ifdef MP-WEIXIN
					if (uni.getStorageSync('sendMsg')) {
						wx.requestSubscribeMessage({
							tmplIds: this.arr,
							success(re) {
								var datas = JSON.stringify(re);
								if (datas.indexOf("accept") != -1) {
									// console.log(re)
								}
							},
							fail: (res) => {
								// console.log(res)
							}
						})
					}
					// #endif
					uni.navigateTo({
						url: e
					})

				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			getUserInfo() {
				this.$Request.get("/app/user/selectUserById").then(res => {
					if (res.code == 0) {
						this.userName = res.data.userName
						this.avatar = res.data.avatar ? res.data.avatar : '../../../static/logo.png'

					}
				});
			},
			getOrder() {
				this.$Request.get("/app/orders/selectStaffUserStatistics").then(res => {
					if (res.code == 0) {
						this.dayCount = res.data.dayCount
						this.count = res.data.count
						this.ranKing = res.data.ranKing

					}
				});
			},
			// 在线客服
			goChat() {
				let token = this.$queue.getData('token');
				if (token) {
					// #ifdef MP-WEIXIN
					if (uni.getStorageSync('sendMsg')) {
						wx.requestSubscribeMessage({
							tmplIds: this.arr,
							success(re) {
								var datas = JSON.stringify(re);
								if (datas.indexOf("accept") != -1) {
									// console.log(re)
								}
							},
							fail: (res) => {
								// console.log(res)
							}
						})
					}
					// #endif
					uni.navigateTo({
						url: '/my/setting/chat'
					});
				} else {
					uni.navigateTo({
						url: '/my/setting/customer'
					});
				}
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f5f5f5;
	}

	.bg {
		background-color: #FFFFFF;
	}

	.box {
		width: 690upx;
		margin: 0 auto;
		height: 140upx;
		background: #557EFD;
		// border-radius: 16upx 16upx 0px 0px;
		border-radius: 24upx;
		color: #FFFFFF;
		padding: 0upx 30upx;

	}

	.images {
		width: 11upx;
		height: 18upx;
	}
</style>
